import request from '@/utils/request'
import { TaskInfoVo, Video } from './type'
const baseUrl = '/vod'
/**
 * 根据文件的md5获取未上传完的任务
 * @param identifier 文件md5
 */
export const reqTaskInfo = (identifier: string) =>
  request.get<any, ResponseData<TaskInfoVo>>(`${baseUrl}/${identifier}`)

/**
 * 初始化一个分片上传任务
 * @param identifier 文件md5
 * @param fileName 文件名称
 * @param totalSize 文件大小
 * @param chunkSize 分块大小
 */
export const reqCreateTask = (
  identifier: string,
  fileName: string,
  totalSize: number,
  chunkSize: number,
) =>
  request.post<any, ResponseData<TaskInfoVo>>(`${baseUrl}`, {
    identifier,
    fileName,
    totalSize,
    chunkSize,
  })

/**
 * 获取预签名分片上传地址
 * @param identifier 文件md5
 * @param partNumber 分片编号
 */
export const reqPreSignUrl = (identifier: string, partNumber: number) =>
  request.get<any, ResponseData<string>>(
    `${baseUrl}/${identifier}/${partNumber}`,
  )

/**
 * 合并分片
 * @param identifier
 */
export const reqMerge = (identifier: string) =>
  request.post<any, ResponseData>(`${baseUrl}/merge/${identifier}`)

export const reqDeleteVideo = (data: Video) =>
  request.post<any, ResponseData>(`${baseUrl}/deleteVideo`, data)
